/* 
   Copyright 2012 Ryne Okimoto

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package tests;

import static org.junit.Assert.*;
import java.io.File;
import manager.FileManager;
import org.junit.Test;

public class FileManagerTests {

	String fn = "testfile.rcp";
	
	@Test
	public void testFileManager() {
		FileManager fm = new FileManager();
		assertNull(fm.getData());
	}

	@Test
	public void testFileManagerString() {
		@SuppressWarnings("unused")
		FileManager fm = new FileManager(fn);
		File tf = new File(FileManager.getDefaultRecipePath() + fn);
		
		assertTrue(tf.exists());
		tf.delete();
	}

	@Test
	public void testGetData() {
		FileManager fm = new FileManager(FileManager.getDefaultRecipePath() + fn);
		fm.createRecipe("test", "testing", "1 L milk", "directions", "", "file");
		assertTrue(fm.getData().getRecipeName().equals("test"));
		assertTrue(fm.getData().getCategory().equals("testing"));
		assertTrue(fm.getData().getListOfIngredientsAsString().equals("1 L milk"));
		assertTrue(fm.getData().getInstructions().equals("directions"));
	}

	@Test
	public void testCreateRecipe() {
		FileManager fm = new FileManager(FileManager.getDefaultRecipePath() + fn);
		fm.createRecipe("test", "testing", "1 L milk", "directions", "", "file");
		String rec = 
				"Recipe name: test\n" +
				"Category: testing\n" +
				"Image: \n" +
				"Tags: file\n" +
				"Ingredients: \n1 L milk\n" +
				"Directions: \ndirections";
		
		assertEquals("Strings should be equal", rec, fm.createString());
	}

	@Test
	public void testCreateString() {
		testCreateRecipe();
	}
}
